package com.itheima.mapper;

import com.itheima.pojo.OrderSetting;
import org.apache.ibatis.annotations.*;

import java.util.Date;
import java.util.List;
@Mapper
public interface OrderSettingMapper {
    /**
     * 批量添加预约设置
     * @param orderSettings
     */
    void batchAdd(@Param("list") List<OrderSetting> orderSettings);

    /**
     * 根据日期更新可预约人数
     * @param orderSetting
     */
    void updateNumberByDate(OrderSetting orderSetting);

    /**
     * 根据日期查询预约设置
     * @param orderDate
     * @return
     */
    @Select("SELECT * FROM t_ordersetting WHERE orderDate = #{orderDate}")
    OrderSetting findByDate(Date orderDate);

    /**
     * 获取某个月的预约设置数据
     * @param beginDate
     * @param endDate
     * @return
     */
    @Select("SELECT * FROM t_ordersetting WHERE orderDate BETWEEN #{beginDate} AND #{endDate}")
    List<OrderSetting> getOrderSettingByMonth(@Param("beginDate") Date beginDate,
                                              @Param("endDate") Date endDate);

    /**
     * 更新已预约人数
     * @param orderDate
     */
    @Update("UPDATE t_ordersetting SET reservations = reservations + 1 WHERE orderDate = #{orderDate} AND reservations < number")
    int addReservation(@Param("orderDate") Date orderDate);

    /**
     * 新增预约设置
     * @param orderSetting
     */
    @Insert("INSERT INTO t_ordersetting (orderDate, number, reservations) VALUES (#{orderDate}, #{number}, #{reservations})")
    void insert(OrderSetting orderSetting);
}